import java.util.Arrays;
import java.util.List;


/**
 * @author kuozhi
 */
public class LeetCode539 {
    public static void main(String[] args) {
        System.out.println(findMinDifference(List.of("00:00", "04:00", "22:00")));
    }

    public static int findMinDifference(List<String> timePoints) {
        final int maxMinute = 1440;
        if (timePoints.size() > maxMinute) {
            return 0;
        }

        int[] minute = new int[timePoints.size()];
        for (int i = 0; i < timePoints.size(); i++) {
            String[] time = timePoints.get(i).split(":");
            minute[i] = Integer.parseInt(time[0]) * 60 + Integer.parseInt(time[1]);
        }

        Arrays.sort(minute);

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < minute.length; i++) {
            int diff = Math.abs(minute[i] - minute[i - 1]);
            diff = Math.min(diff, maxMinute - diff);
            min = Math.min(diff, min);
        }

        int last = minute[minute.length - 1] - minute[0];
        min = Math.min(min, Math.min(last, maxMinute - last));

        return min;
    }
}
